<template>

    <div class="app-container">

      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
        <el-table-column label="编号">
          <template #default="scope">
            <el-button link type="primary" @click="handleApprove(scope.row)">{{scope.row.apply.number}}</el-button>

          </template>
        </el-table-column>
        <el-table-column label="数量" prop="num">
          <template #default="scope">
            {{scope.row.apply.num}}
          </template>
        </el-table-column>
        <el-table-column label="申请人" prop="createUserName">
          <template #default="scope">
            {{scope.row.apply.createUserName}}
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="remark">
          <template #default="scope">
            {{scope.row.apply.remark}}
          </template>
        </el-table-column>
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="paging.pageNum"
        :limit.sync="paging.pageSize"
        @pagination="onPageChange"
      />
      <approve ref="approve" @sub="onSub"></approve>
    </div>


    
  </template>
  
  <script>
  import api from "./api.js";
  import { getCurrentInstance} from 'vue'
  import Approve from './approve.vue'
  
  export default {
    name: "AssetInApply",
    components: {
      Approve: Approve
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        list: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        paging: {
          pageNum: 1,
          pageSize: 10,
        },
        // 查询参数
        queryParams: {
          configName: null,
          configDesc: null,
          configType: null,
          orderType: null,
          status: null,
          createUserId: null,
          updateUserId: null
        },
        // 表单参数
        form: {},
      };
    },
    created() {
      this.getList();
    },
    setup() {
      const { proxy } = getCurrentInstance();
      const { apply_state } = proxy.useDict("apply_state");
      return {
        apply_state
      }
    },
    methods: {
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        const {pageNum, pageSize} = this.paging;

        const query = {...this.queryParams};
        const pageReq = {page: pageNum - 1, size: pageSize};
        api.list(query, pageReq).then(response => {
          const { content, totalElements } = response
          this.list = content;
          this.total = totalElements;
          this.loading = false;
        });
      },
      onPageChange({page, limit}) {

        this.paging.pageNum = page;
        this.paging.pageSize = limit;
        this.getList();
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          configName: null,
          configDesc: null,
          configType: null,
          orderType: null,
          status: 0,
          createTime: null,
          updateTime: null,
          createUserId: null,
          updateUserId: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 修改按钮操作 */
      handleApprove(row) {
        this.$refs.approve.open(row);
      },
      onSub() {
        this.getList();
      }
    }
  };
  </script>
  